﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using BrainTechLLC.ThreadSafeObjects;
using LinFu.AOP.Interfaces;

namespace BrainTechLLC
{
	[Serializable, AttributeUsage(AttributeTargets.Property)]
	public class ObservablePropertyAttribute : GenericAttributeBool, IReadableAttribute
	{
		public bool IsObservable { get { return Val; } }

		public ObservablePropertyAttribute (bool isObservable) : base(isObservable) { }
		public ObservablePropertyAttribute() : base(true) { }		

		public void DoWorkBefore(IInvocationContext context, string propertyName, object thisObject, object oldValue, object newValue)
		{
			Type t = thisObject.GetType();
			Observable observable = Lookups.ObservableProperties.Get(t.Name + "." + propertyName);
			observable.RaiseNotify(true, thisObject, context, oldValue, newValue);
		}

		public void DoWorkAfter(IInvocationContext context, string propertyName, object thisObject, object returnValue)
		{
			Type t = thisObject.GetType();
			Observable observable = Lookups.ObservableMethods.Get(t.Name + "." + propertyName);
			observable.RaiseNotify(false, thisObject, context, returnValue, null);
		}
	}
}

